// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import Debug_hierachyViewer from './Debug_hierachyViewer';
const {ccclass, property} = cc._decorator;

@ccclass
export default class Debug_hierachyViewer_singleLabel extends cc.Component {

    
    viewerManager: Debug_hierachyViewer = null;
    xOffset: number= 0;

    @property(cc.Label)
    fontText: cc.Label = null;

    targetNode: cc.Node = null;
    targetLevel: number = 0;
    fontSize: number = 30;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    showLabel(hasChildren: boolean) {
        this.fontText = this.getComponent(cc.Label);
        //this.fontSize = this.targetLevel > this.viewerManager.fontSizeMap.length ? this.viewerManager.fontSizeMap[this.viewerManager.fontSizeMap.length - 1] : this.viewerManager.fontSizeMap[this.targetLevel];
        this.xOffset = this.targetLevel * 34;
        this.node.x = this.xOffset;
        this.fontText.string = '';

        this.fontText.string += (this.targetNode.activeInHierarchy ? '●' : '○');
        this.fontText.string += hasChildren && this.isHiddenChildren() ? '[+]' : '';
        this.fontText.string +=  this.targetNode.name;
        //this.frontText.fontSize = this.fontSize;
        this.fontText.getComponent(cc.Button).clickEvents[0].customEventData = this.targetNode.uuid;
    }

    isHiddenChildren(): boolean{
        let tempList: string[] = this.viewerManager.ignoreList;
        for (let i = 0; i < tempList.length; i++){
            if (tempList[i] == this.targetNode.uuid) {
                return true;
            }
        }
        return false;
    }

    // update (dt) {}
}
